<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<% String path=request.getContextPath(); String basePath=request.getScheme()+ "://" + request.getServerName() + ":" + request.getServerPort() + path+ "/"; %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head>
<base href="<%=basePath%>">
<title>险别添加</title>
<%@ include file="/WEB-INF/jsp/common/common.jsp" %>
<style type="text/css">
.input_text{
width: 250px;
}
.select_1{
width: 250px;
}
.content_table_1 th{background-color:#ECF5FC; color:#343233; width:11%; text-align:center; line-height:23px; font-family: "宋体"; font-size:12px; font-weight:normal; border-bottom:2px #bbcddb solid;}
</style>
<script src="js/jquery.validate.js" type="text/javascript" ></script>
<script src="js/jquery.divbox.js" type="text/javascript"></script>
<script src="js/json2.js" type="text/javascript"></script>


<script type="text/javascript">
var startP=1;
var prodType='${prodType}';
var prodCode='${prodCode}';
var useRiskCode="";
var Formstatus=true;

$(document).ready(function() {
	loadPlan({current:1,size:6,prodCode:prodCode});
});

function loadPlan(param){
	$.openLoading();
	$.ajax({
		url : "noCarProduct/loadPlan",
		type : 'POST',
		async : true,
		dataType:'json',
		data:param,
		success : function(page) {
			$.closeLoading();
			if($.validate(page))return;
			startP = page.current;
			var buttonStr = "<a href='javascript:void(0)' onClick='editRiskReq(this);return false'>编辑</a>&nbsp;<a href='javascript:void(0)' onClick='delRisk(this)'>删除</a>";
			var tableContent = creatTable("riskCode@TDH,prodCode@TDH,nField1,riskName,amount,nField6,nField4,nField7,nField9,nField12,nField11,nField10,nField8,riskCalType@TDH,riskCalDscp",page,buttonStr);
			var tableObj = $("#ProdPlanTable");
			tableObj.find("tbody").remove();
			tableObj.append(tableContent);
			var strPage = creatChannelPage3(startP,6,page.maxPage,"13");
			var pageDIV = $("#ProdPlanpageDIV");
			pageDIV[0].innerHTML="";
			pageDIV.append(strPage);
		}
	});
}
function queryProdPlan(pagenum){
	loadPlan({current:pagenum,size:6,prodCode:prodCode});
}
function addRisk(param){
//	console.log(param);
	if(!Formstatus){
		$.message("error","正在处理中");
		return;
	}
	Formstatus=false;
	$.openLoading();
	$.ajax({
		url : "noCarProduct/saveRisk",
		type : 'POST',
		async : true,
		dataType:'json',
		data:param,
		success : function(obj) {
			Formstatus=true;
			$.closeLoading();
			if($.validate(obj))return;
			vreset();
			loadPlan({current:1,size:6,prodCode:prodCode});
		}
	});
}

//添加险别校验 得到校验规则后再进行修改
function add(){
	if($("#riskCode").val()==""){
		$.message("error","请选择险别");
    	return;
	}
	if($("#riskCalType").val()==""){
		$.message("error","请选择保费计算方式");
    	return;
	}
//	checkAmount($("#amount").val());
/*
	if($.trim($("#cField9").val())==""){
		$.message("error","请输入保险标的");
    	return;
	}
//获取节点对应的值 
N_FIELD_1	序号
riskCode	投保险别

AMOUNT		累计责任限额
N_FIELD_6	每次事故责任限额
N_FIELD_4	投保人数
N_FIELD_7	每座/每人赔偿责任限额（元）

N_FIELD_9	基准保费（元）
NField12	含税保费

N_FIELD_11	基准费率（‰）
N_FIELD_10	实际费率（‰）

N_FIELD_8	调整系数乘积

*/
	var riskCode = $('#riskCode').val();	//险别代码
	var riskName = $('#riskCode').find("option:selected").text();	//险别名称
	var amount= $("#amount").val();	
	var nField6= $("#nField6").val();	
	var nField4= $("#nField4").val();	
	var nField7= $("#nField7").val();	
	var nField9= $("#nField9").val();	
	var nField12= $("#nField12").val();	
	var nField11= $("#nField11").val();	
	var nField10= $("#nField10").val();	
	var nField8= $("#nField8").val();	
	var riskCalType= $("#riskCalType").val();
	var prmryFlag= $("#prmryFlag").val();
	addRisk({prodType:prodType,prodCode:prodCode,riskCode:riskCode,riskName:riskName,riskCalType:riskCalType,amount:amount,nField6:nField6,nField4:nField4,nField7:nField7,nField9:nField9,nField12:nField12,nField11:nField11,nField10:nField10,nField8:nField8,prmryFlag:prmryFlag});
}

/**
 * 重置
 */
function vreset(){
	$("#riskCode").val("");
	$("#riskCalType").val("");
	$("#amount").val("");
	$("#nField6").val("");
	$("#nField4").val("");
	$("#nField7").val("");
	$("#nField9").val("");
	$("#nField12").val("");
	$("#nField11").val("");
	$("#nField10").val("");
	$("#nField8").val("");
	$("#prmryFlag").val("");
	$("#prmryFlagText").val("");
}
/**
 * 删除险别
 */
function delRisk(obj){
	var riskCode  = $(obj).parent('td').parent('tr')[0].childNodes[0].innerHTML;
	var indexId  =  $(obj).parent('td').parent('tr')[0].childNodes[2].innerHTML;

	$.dialog({
		type: "warn",//success,error
		content: "您确定要删除该险别吗？",
		onOk: function() {
			deleteRisk(prodCode,riskCode,indexId);
		}
	});
}
function deleteRisk(prodCode,riskCode,indexId){
	
	$.openLoading();
	$.ajax({
		url : "noCarProduct/riskDelete",
		type : 'POST',
		async : true,
		dataType:'json',
		data:{prodCode:prodCode,riskCode:riskCode,nField1:indexId},
		success : function(obj) {
			$.closeLoading();
			if($.validate(obj))return;
			
			loadPlan({current:1,size:6,prodCode:prodCode});
		}
	});
}
var nField1=0;
//打开编辑窗口，编辑“组合方案信息”
function editRiskReq(obj){
	/*
		页面中已添加险别列表中获取节点元素顺序
		riskCode@TDH,prodCode@TDH,nField1,riskName,
		amount,nField6,nField4,nField7,nField9,nField12,nField11,nField10,nField8,riskCalType@TDH,riskCalDscp
	*/
	var editTr = $(obj).parent('td').parent('tr')[0];
	var riskCode = editTr.childNodes[0].innerHTML;
	useRiskCode=riskCode;
	nField1 = editTr.childNodes[2].innerHTML;
	var riskName = editTr.childNodes[3].innerHTML;
	var amount = editTr.childNodes[4].innerHTML;
	var nField6 = editTr.childNodes[5].innerHTML;
	var nField4 = editTr.childNodes[6].innerHTML;
	var nField7 = editTr.childNodes[7].innerHTML;
	var nField9 = editTr.childNodes[8].innerHTML;
	var nField12 = editTr.childNodes[9].innerHTML;
	var nField11 = editTr.childNodes[10].innerHTML;
	var nField10 = editTr.childNodes[11].innerHTML;
	var nField8 = editTr.childNodes[12].innerHTML;
	var riskCalType = editTr.childNodes[13].innerHTML;
	
	$("#eriskName").val(riskName);
	$("#eamount").val(amount);
	$("#enField6").val(nField6);
	$("#enField4").val(nField4);
	$("#enField7").val(nField7);
	$("#enField9").val(nField9);
	$("#enField12").val(nField12);
	$("#enField11").val(nField11);
	$("#enField10").val(nField10);
	$("#enField8").val(nField8);
	$("#eriskCalType").val(riskCalType);
	$("#editPlanDiv").OpenDiv();
}

function saveEditRisk(){
	if($("#eriskCalType").val()==""){
		$.message("error","请选择保费计算方式");
    	return;
	}
    //校验 
//    checkAmount($("#eamount").val());
/*   var nField17= $("#enField17").val();
    if($.trim(nField17)==''){
    	$.message("error","输入基准费率(‰)");
		return;
    }

 	var nField19= $("#enField15").val();
    if($.trim(nField19)==''){
    	$.message("error","输入调整系数调整系数");
		return;
    }
	var nField6= $("#enField6").val();
	 if($.trim(nField6)==''){
	    	$.message("error","输入每次事故赔偿限额(元)");
			return;
	}
*/
	var riskCode = $('#eriskCode').val();
	var riskCalType= $("#eriskCalType").val();
	var amount = $("#eamount").val();
	var nField6= $("#enField6").val();
	var nField4= $("#enField4").val();
	var nField7= $("#enField7").val();
	var nField9= $("#enField9").val();
	var nField12= $("#enField12").val();
	var nField11= $("#enField11").val();
	var nField10= $("#enField10").val();
	var nField8= $("#enField8").val();
	updateRiskInfo({prodType:prodType,prodCode:prodCode,riskCode:useRiskCode,riskCalType:riskCalType,amount:amount,nField6:nField6,nField4:nField4,nField7:nField7,nField9:nField9,nField12:nField12,nField11:nField11,nField10:nField10,nField8:nField8,nField1:nField1});
}


function updateRiskInfo(param){
	if(!Formstatus){
		$.message("error", "正在处理中");
		return;
	}
	Formstatus=false;
	$.openLoading();
	$.ajax({
		url : "noCarProduct/riskUpdate",
		type : 'POST',
		async : true,
		dataType:'json',
		data:param,
		success : function(obj) {
			Formstatus=true;
			$.closeLoading();
			if($.validate(obj))return;
			loadPlan({current:1,size:6,prodCode:prodCode});
			closeEditPlanDiv();
		}
	});
}


function closeEditPlanDiv(){
	$("#editPlanDiv").CloseDiv();
}
//主附险标志
function addMainSign(){
	var otherCode = $('#riskCode :selected').attr('class');//主附险标志取值
	
	if(otherCode==0){
		$('#prmryFlagText').val('主险');
		$('#prmryFlag').val('0');
	}else if(otherCode==1){
		$('#prmryFlagText').val('附加险');
		$('#prmryFlag').val('1');
	}else{
		$('#prmryFlagText').val('');
		$('#prmryFlag').val('');
	}
}
//校验 amount 
function checkAmount(amount){
	if(amount==""){
		$.message("error","请选填写累计责任限额"); 
    	return;
	}
	//小数点. 后面只能保留2位小数
	var reg = new RegExp("^(([1-9][0-9]*)|0)(\.[0-9]{1,2})?$");
    var flag= reg.test(amount);
    if(!flag){
    	$.message("error","输入保险金额(元)最多保留2位小数");
    	return;
    }
    //没有小数点情况下，输入金额长度不能超过8位数字
    var strval = amount+"";
    var idx = strval.indexOf('.');
    if(idx==-1){
    	if(strval.length>8){
    		$.message("error","输入保险金额(元)长度不能超过8位数字");
    		return;
    	}
    }
}
</script>
<style>
	.input_text {
	padding-left: 3px;
	}
	</style>
</head>
<body>
<div class="right">
	      <div class="current">
	           <table class="current_table_1">
	              <tbody>
		              <tr>
		                <td><img src="./images/current_1.jpg"></td>
		                  <td class="current_table_1_td"><img src="images/current_1.png">&nbsp;您现在的位置：&nbsp;
			                  <span style=" color:#136bab; ">财险产品管理
			                  <span style="padding:0 5px; font-weight:bold; line-height:28px;">&gt;</span>产品配置
			                  <span style="padding:0 5px; font-weight:bold; line-height:28px;">&gt;</span>添加险别
			                  </span>
		                  </td>
		                  <td><img src="./images/current_3.jpg"></td>
		              </tr>
	           	  </tbody>
	           </table>
	      </div>
	      <div>
			<form id="inputForm" >
			<table class="table_05">
	              <tbody>
		    		  <tr>
 		              	<td style="line-height:23px;">
 		              		<font color="#3876bf"><b>产品代码：</b></font> ${prodCode}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#3876bf"><b>产品名称：</b></font>${prodName}
 		              	</td>
		              </tr>
	           	  </tbody>
	         </table> 
	        <table class="table_05">
	              <tbody>
		              <tr>
		                  <td colspan="4" style=" font-size:12px; font-weight:bold; text-align:left;color:#3876bf; line-height:17px; background-image:url(images/centent_1.jpg)">险别添加</td>
		              </tr>
		    		  <tr>
		                  <th width="35%">险别：</th>
		                  <td width="15%"><select id="riskCode" name = "riskCode" class="select_1" style="visibility: visible;"onchange="addMainSign()">
		                  					<option value="">------------------请选择------------------</option>
		                  					<c:forEach var ="riskCode" items="${riskCode}">
		                  						<option id="riskCode" class="${riskCode.otherCode}" value="${riskCode.code}">${riskCode.codeName}</option>
		                  					</c:forEach>
		                  				  </select><span class="red">*</span>
		                   </td>
		                   <th width="35%">保费计算方式：</th>
		                   <td width="15%"><select id="riskCalType" name = "riskCalType" class="select_1" style="visibility: visible;">
		                  					<option value="">------------------请选择------------------</option>
		                  					<c:forEach var ="riskTypeCal" items="${riskCalTypeList}">
		                  						<option value="${riskTypeCal.code}">${riskTypeCal.codeName}</option>
		                  					</c:forEach>
		                  				  </select>
		                  <span class="red">*</span></td>
		              </tr>
		              <tr>
		              	  <th width="40%">累计责任限额(元)：</th>
		                  <td width="15%"><input id="amount" name = "amount" type="text" maxlength="20" class="input_text" onKeyUp="clearNoNum(event,this)" onBlur="checkNum(this)"></td>
		                  <th width="30%">每次事故责任限额(元)：</th>
		                  <td width="15%"><input id="nField6" name = "nField6" type="text" maxlength="15" class="input_text" onKeyUp="clearNoNum(event,this)" onBlur="checkNum(this)"></td>
		                  
		              </tr>
		              <tr>
		                  <th width="40%">投保人数：</th>
		                  <td width="15%"><input id="nField4" name = "nField4" type="text" maxlength="15" class="input_text" onKeyUp="clearNoNum(event,this)" onBlur="checkNum(this)"></td>
		                  <th width="30%">每座/每人赔偿责任限额(元)：</th>
		                  <td width="15%"><input id="nField7" name = "nField7" type="text" maxlength="15" class="input_text" onKeyUp="clearNoNum(event,this)" onBlur="checkNum(this)"></td>
		              </tr>
		              <tr>
		                  <th width="40%">基准保费(元)：</th>
		                  <td width="15%"><input id="nField9" name = "nField9" type="text" maxlength="15" class="input_text" onKeyUp="clearNoNum(event,this)" onBlur="checkNum(this)"></td>
		                  <th width="30%">含税保费(元)：</th>
		                  <td width="15%"><input id="nField12" name = "nField12" type="text" maxlength="15" class="input_text" onKeyUp="clearNoNum(event,this)" onBlur="checkNum(this)"></td>
		              </tr>
		              <tr>
		                  <th width="40%">基准费率(%)：</th>
		                  <td width="15%"><input id="nField11" name = "nField11" type="text" maxlength="20" class="input_text" onKeyUp="clearNoNum(event,this)" onBlur="checkNum(this)"></td>
		                  <th width="30%">实际费率(%)：</th>
		                  <td width="15%"><input id="nField10" name = "nField10" type="text" maxlength="20" class="input_text" onKeyUp="clearNoNum(event,this)" onBlur="checkNum(this)"></td>
		              </tr>
		              <tr>
		                  <th width="40%">调整系数乘积：</th>
		                  <td width="15%"><input id="nField8" name = "nField8" type="text" maxlength="20" class="input_text" onKeyUp="clearNoNum(event,this)" onBlur="checkNum(this)"></td>
		                  <th width="35%">主附险标志：</th>
		                  <td width="15%"><input id="prmryFlagText" name = "prmryFlagText"  type="text" maxlength="20" class="input_text" readonly="true" style=" background-color: #ccc;" onBlur="checkNum(this)"><span class="red">*</span></td>
		              </tr>
<!-- 	              <tr>
		                  <th width="40%">免赔条件：</th>
		                  <td colspan="3"><textarea name="cField10" id="cField10"  maxlength="500"  rows="5" class="textarea_1" style="resize:none"></textarea></td>
		              </tr>  -->	
	           	  </tbody>
	         </table> 
	         <input id="prmryFlag" name = "prmryFlag"  type="text" maxlength="20" class="input_text" style="display: none"  >
	         <div align="center">
	             <input class="input_button_1" name="" type="button" onclick="add()" value="保存">&nbsp;&nbsp;
		         <input class="input_button_1" name="" type="button" onclick="vreset()"value="重置">
	         </div>
	         </form>
	      </div>
	      
 	      <!-- 险别列表 -->
	      <div style="margin-top: 5px;">
	         <table class="table_02" id="ProdPlan" align="center" >
				<tbody>
					<tr>
						   <td colspan="6" style=" font-size:12px; font-weight:bold; text-align:left;color:#3876bf; line-height:27px;height:27px; background-image:url(images/centent_1.jpg)">&nbsp;已添加险别列表</td>
					</tr>
					<tr>
						<td>
							<table id="ProdPlanTable" class="content_table_1">
								<thead>
									<tr class="f1">
									   <th style="width:4%">序号</th><!-- nFiled1 -->
									   <th style="width:6%">险别</th><!-- riskCode -->
					                   <th style="width:6%">累计责任限额(元)</th><!-- amount -->
					                   <th style="width:6%">每次事故责任限额(元)</th><!-- nField6 -->
					                   <th style="width:6%">投保人数</th><!-- nField4 -->
					                   <th style="width:6%">每座/每人赔偿责任限额(元)</th><!-- nField7 -->
					                   <th style="width:6%">基准保费(元)</th><!-- nField9 -->
					                   <th style="width:6%">含税保费(元)</th><!-- nField12 -->
					                   <th style="width:6%">基准费率(%)</th><!-- nField11 -->
					                   <th style="width:6%">实际费率(%)</th><!-- nField10 -->
								       <th style="width:6%">调整系数乘积</th><!-- nField8 -->
								       <th style="width:8%">保费计算方式</th><!-- riskCalType -->
								       <th style="width:6%">操作</th>
					              	</tr>
								</thead>
								<tbody>
								</tbody>
							</table>
							<div id="ProdPlanpageDIV"  class="page"></div>
						</td>
					</tr>
				</tbody>
			</table>
	      </div>     
	

</div>
	<!--   	添加模板 DIV 默认隐藏-->
	<div id="editPlanDiv"  style="display:none;overflow-y:auto; width:60%">
			<input type="hidden" id="row_num" name="row_num" value="0"/>
			<div class="table_title_div">
					<table class="table_title" style='width:100%;height: 20px;'>
						<tr>
						<td width="10%"></td>
						<td width="80%" id="interfaceName"></td>
						<td width="10%" align="right"><img src="/manager/images/closedown.gif" alt="关闭"  onclick="closeEditPlanDiv()"/></td>
						</tr>
					</table>
			</div>
			<!-- 修改id 名 -->
			<table class="table_02" id="addtempletTable" align="center">
				<tbody>
					<tr>
						<td>
							<table id="coverageTable"  class="content_table_1" style="height:120px;">
								
								<tbody>
									<tr>
					                  <td width="40%" style="text-align:right;border-right:0px;">险别：&nbsp;&nbsp;</td>
					                  <td width="60%" style="text-align:left"><input type="text" id="eriskName" class="input_text"  readonly="readonly" style=" background-color: #ccc;"></td>
					                </tr>
					                <tr>  
					                  <td width="40%" style="text-align:right;border-right:0px;">累计责任限额(元)：&nbsp;&nbsp;</td>
					                  <td width="60%" style="text-align:left"><input id="eamount" type="text" maxlength="20" class="input_text" onKeyUp="clearNoNum(event,this)" onBlur="checkNum(this)"><span class="red">*</span></td>
					                </tr>
 					                <tr>  
					                  <td width="40%" style="text-align:right;border-right:0px;">每次事故责任限额(元)：&nbsp;&nbsp;</td>
					                  <td width="60%" style="text-align:left"><input id="enField6" type="text" class="input_text" maxlength="15" onKeyUp="clearNoNum(event,this)" onBlur="checkNum(this)"></td>
					                </tr>
					                <tr>  
					                  <td width="40%" style="text-align:right;border-right:0px;">投保人数：&nbsp;&nbsp;</td>
					                  <td width="60%" style="text-align:left"><input id="enField4" type="text" class="input_text" maxlength="15" onKeyUp="clearNoNum(event,this)" onBlur="checkNum(this)"></td>
					                </tr>
					                <tr>  
					                  <td width="40%" style="text-align:right;border-right:0px;">每座/每人赔偿责任限额(元)：&nbsp;&nbsp;</td>
					                  <td width="60%" style="text-align:left"><input id="enField7" type="text" class="input_text" maxlength="15" onKeyUp="clearNoNum(event,this)" onBlur="checkNum(this)"></td>
					                </tr>
					                <tr>  
					                  <td width="40%" style="text-align:right;border-right:0px;">基准保费(元)：&nbsp;&nbsp;</td>
					                  <td width="60%" style="text-align:left"><input id="enField9" type="text" class="input_text" maxlength="15" onKeyUp="clearNoNum(event,this)" onBlur="checkNum(this)"></td>
					                </tr>
					                <tr>  
					                  <td width="40%" style="text-align:right;border-right:0px;">含税保费(元)：&nbsp;&nbsp;</td>
					                  <td width="60%" style="text-align:left"><input id="enField12" type="text" class="input_text" maxlength="15" onKeyUp="clearNoNum(event,this)" onBlur="checkNum(this)"></td>
					                </tr>
					                <tr>  
					                  <td width="40%" style="text-align:right;border-right:0px;">基准费率(%)：&nbsp;&nbsp;</td>
					                  <td width="60%" style="text-align:left"><input id="enField11" type="text" class="input_text" maxlength="15" onKeyUp="clearNoNum(event,this)" onBlur="checkNum(this)"></td>
					                </tr>
					                <tr>  
					                  <td width="40%" style="text-align:right;border-right:0px;">实际费率(%)：&nbsp;&nbsp;</td>
					                  <td width="60%" style="text-align:left"><input id="enField10" type="text" class="input_text" maxlength="15" onKeyUp="clearNoNum(event,this)" onBlur="checkNum(this)"></td>
					                </tr>
					                <tr>  
					                  <td width="40%" style="text-align:right;border-right:0px;">调整系数乘积：&nbsp;&nbsp;</td>
					                  <td width="60%" style="text-align:left"><input id="enField8" type="text" class="input_text" maxlength="15" onKeyUp="clearNoNum(event,this)" onBlur="checkNum(this)"></td>
					                </tr>
					                <tr>
					                  <td width="40%" style="text-align:right;border-right:0px;">保费计算方式：&nbsp;&nbsp;</td>
					                  <td width="60%" style="text-align:left"><select id="eriskCalType" class="select_1" style="visibility: visible;width:250px;">
		                  					<option value="">------------------请选择------------------</option>
		                  					<c:forEach var ="eriskTypeCal" items="${riskCalTypeList}">
		                  						<option value="${eriskTypeCal.code}">${eriskTypeCal.codeName}</option>
		                  					</c:forEach>
		                  				  </select><span class="red">*</span></td>
					                </tr>
<!-- 				                <tr>  
					                  <td width="40%" style="text-align:right;border-right:0px;">免赔条件：&nbsp;&nbsp;</td>
					                  <td width="60%" style="text-align:left"><textarea id="ecField10"  maxlength="500"  rows="5" class="textarea_1" style="resize:none;width: 250px"></textarea></td>
					                </tr>  -->	
								</tbody>
							</table>
							
						</td>
					</tr>
				</tbody>
			</table>
			<div align="center">
			   <input class="input_button_3" name="" type="button" onclick="saveEditRisk()" value="保存">&nbsp;&nbsp;
	           <input class="input_button_3" name="" type="button" onclick="closeEditPlanDiv()" value="取消">
			</div>
	</div>
	
</body>
</html>